package com.company;


import java.util.*;

public class Task2 {
    public static void main(String[] args) {
        //todo 2.将玩家姓名和游戏得分录入系统，输出排名前三的玩家和其得分。
        // 玩家A：10分，玩家B：40分，玩家C：30分，玩家D：20分，玩家E：50分
        TreeSet<Play> set = new TreeSet<>();
        set.add(new Play("A", 10));
        set.add(new Play("B", 40));
        set.add(new Play("C", 30));
        set.add(new Play("D", 20));
        set.add(new Play("E", 50));
        int i = 0;
        for(Object o:set){
            if(i<3){
                System.out.println(o);
            }
            i++;

        }


    }

    public static class Play implements Comparable<Play>{
        private String name;
        private int num;

        public Play(String name,int num){
            this.name = name;
            this.num = num;
        }

        @Override
        public String toString() {
            return "name=" + name  +", num=" + num ;
        }

        @Override
        public int compareTo(Play o) {
            return  o.num - this.num;
        }
    }

}
